home *** CD-ROM | disk | FTP | other *** search
- Path: hops.cs.jhu.edu!lasher
- From: lasher@hops.cs.jhu.edu (John E. Davis)
- Newsgroups: comp.lang.c
- Subject: Re: goto
- Date: 13 Mar 1996 19:45:49 GMT
- Organization: JHU computer science
- Message-ID: <4i78ld$43f@blaze.cs.jhu.edu>
- References: <Pine.OSF.3.91.960313102715.10701D-100000@io.UWinnipeg.ca>
- NNTP-Posting-Host: hops.cs.jhu.edu
- X-Newsreader: TIN [version 1.2 PL2]
-
- Bill Simpson (wsimpson@uwinnipeg.ca) expostulated:
- > There was a goto thread lately, and my problem is to state this algorithm
- > cleanly without gotos (which I think is easy, but my attempts have been
- > failures).
-
- > 0. x=0;
- > 1. x+=erand(maxmean);
- > 2. if (urand2()>rate(x)/maxrate)
- > goto step 1
- > 3. if (x<=XMAX)
- > {
- > setdot(x,y,z);
- > goto step 1
- > }
-
- I know I am no expert, but ...
-
- for(x=0;;x+=erand(maxmean))
- {
- if (urand2()>rate(x)/maxrate) continue;
- else if(x<=XMAX) setdot(x,y,z);
- else break;
- }
-
- Although this has no limit on the number of times it is looped through
- ... It looks like it would work ... just add some cort of test to see if
- the loop should end.
-
- john davis
-